<?php
/**
 * Created by PhpStorm.
 * User: wangsentao
 * Date: 2018/2/2
 * Time: 上午11:44
 */

namespace app\admin\controller;

use app\api\controller\Errorcode;
use app\common\Utils\RedisClient;
use app\common\Cache\CAdminUser;

class Oauth
{

    /**
     * 过期时间秒数
     *
     * @var int
     */



    /**
     * 认证授权 用户信息 和 token
     * @param Request $request
     * @return \Exception|UnauthorizedException|mixed|Exception
     * @throws UnauthorizedException
     */
    final function authenticate($request)
    {
        try {
            //验证授权
            $checkclient = $this->certification($request);
            if ($checkclient) {
                return $request;
            }
        } catch (Exception $e) {
            return $this->returnmsg(402, 'Invalid1 authentication credentials.');
        }
    }

    /**
     * 获取用户信息后 验证登录权限
     * @return mixed
     */
    public function certification(array $data = [])
    {
        $redis = new RedisClient();

        $getCacheAccessToken = CAdminUser::getHotUserInfo($data['acc_id']);

        if (!$getCacheAccessToken) {
            return Errorcode::$code['400003'];
        }

        /*if ($getCacheAccessToken['client']['app_key'] != $data['app_key']) {

            return $this->returnmsg(402, 'App_token does not match app_key');  //app_key与缓存中的appkey不匹配
        }*/

        return true;
    }
}